package com.yugao.fintech.antelope.infra.module.dict;

import com.alibaba.cloud.nacos.NacosServiceAutoConfiguration;
import com.yugao.fintech.antelope.infra.module.dict.model.entity.DictItem;
import com.yugao.fintech.framework.assistant.utils.CollectionUtils;
import com.yugao.fintech.framework.assistant.utils.exception.BizException;
import com.yugao.fintech.framework.core.response.Resp;
import com.yugao.fintech.framework.core.response.RetOps;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;


@Service
@ConditionalOnClass({FeignAutoConfiguration.class, NacosServiceAutoConfiguration.class})
public class DictItemCloudApiImpl implements DictItemApi {
    @Autowired
    private FeignDictItemService feignDictItemService;
    @Override
    public Map<String, Map<String, DictItem>> listByCodes(List<String> codes) {
        if (CollectionUtils.isEmpty(codes)) {
            return Collections.emptyMap();
        }
        Resp<Map<String, Map<String, DictItem>>> resp = feignDictItemService.listByCodes(codes);
        RetOps.of(resp).assertSuccess((e) -> new BizException(e.getCode(), e.getMsg()));
        return resp.getData();
    }

    @Override
    public DictItem getDictItem(String dictType, String dictCode) {
        throw new UnsupportedOperationException("为了保证效率, 这里没有实现远程接口, 调用方需要引入dict-biz依赖");
    }

    @Override
    public List<DictItem> listDictItem(String dictCode) {
        throw new UnsupportedOperationException("为了保证效率, 这里没有实现远程接口, 调用方需要引入dict-biz依赖");
    }
}
